<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/8/14
  Time: 17:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/bootstrap/css/bootstrap.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/table/bootstrap-table.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/date/bootstrap-datetimepicker.min.css"/>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/static/sweetalert.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-3.2.1.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/sweetalert.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/table/bootstrap-table.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/date/Moment.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/date/bootstrap-datetimepicker.min.js"></script>
</head>
<body>
<table id="tb"></table>
</body>
<script type="text/javascript">


    function search() {
        var opts = $("#table").bootstrapTable('getOptions');
        var roomstate = $("#roomstate").val();
        var roomtyperoomtypeid = $("#roomtype").val();
        var tabinput = $("#tabInput").val();
        $.ajax({
            "url": "${pageContext.request.contextPath}/room/query",
            "type": "post",
            "data": {
                "roomstate": roomstate,
                "roomtyperoomtypeid": roomtyperoomtypeid,
                "pageNumber": 1,
                "pageSize": 5,
                "tabinput": tabinput
            },
            "dataType": "json",
            "success": function (data) {
                $(".table").bootstrapTable('load', data);
            }
        })
    }


    function del(id) {
        swal({
            title: "您确定要删除这条信息吗",
            text: "删除后将无法恢复，请谨慎操作！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "删除",
            closeOnConfirm: true
        }, function () {
            $.ajax({
                "url": '${pageContext.request.contextPath}/room/del',
                "type": "post",
                "data": {"roomid": id},
                "success": function (data) {
                    $(".table").bootstrapTable('refresh');
                }
            })
        });
    }



    $(function(){




        $("#tb").bootstrapTable({
            url: '${pageContext.request.contextPath}/room/query?tabinput=1',
            columns: [
                {
                    field: 'roomid',
                    title: '编号',
                    width: "250px"
                }, {
                    field: 'roomname',
                    title: '名称',
                    width: "250px"
                }, {
                    title: '类型',
                    formatter: function (index, row, value) {
                        return row.roomtype.roomtype;
                    },
                    width: "250px"
                }, {
                    title: '状态',
                    formatter: function (index, row, value) {
                        if (row.roomstate == 1) {
                            return "消费中"
                        } else if (row.roomstate == 2) {
                            return "未使用"
                        }
                    },
                    width: "250px"
                }, {
                    title: '操作',
                    events: operateEvents,
                    formatter: caozuo
                }],
            clickToSelect: true,
            method: 'post',
            contentType: "application/x-www-form-urlencoded",
            height: 500,
            pageList: [5, 10, 15],
            pageSize: 5,
            pageNumber: 1,
            pagination: true,
            queryParamsType: '',
            queryParams: queryParams,
            sidePagination: 'server'
        });

        function caozuo(value, row, index) {
            var tabinput = $("#tabInput").val();
            return [
                "<a class='del' href=javascript:del(" + row.roomid + ")>删除</a>"
            ].join("");
        }

    });
</script>
</html>
